//
//  ___PROJECTNAMEASIDENTIFIER___AppDelegate.mm
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___ All rights reserved.
//

#import "___PROJECTNAMEASIDENTIFIER___AppDelegate.h"

@implementation ___PROJECTNAMEASIDENTIFIER___AppDelegate
@synthesize window;

- (void)rotate:(id)sender {
	if(sender == sprite)
	{
		sprite.rotation += 10*[vdKernel sharedKernel].deltaTime;
	}
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
	rootNode = [[vdNode alloc] init]; // Creating the root node
	
	/* Create the engine kernel*/
	[vdKernel createSharedKernelWithAPI:OpenGLESAPI2]; // We use OpenGLES 2.0 if possible
	[[vdKernel sharedKernel] attachToWindow:window]; // The engine view will be added to the window
	[[vdKernel sharedKernel] setMaxFPS:60]; // The max FPS is 60 (you may want to use smaller values like 30 ;)
	[[vdKernel sharedKernel] setRootNode:rootNode]; // Setting the root node...
	[[vdKernel sharedKernel] startRendering]; // ...and starting the rendering "loop"
	
	/* Sprite creation */
	sprite = [[vdShape alloc] initWithTexture:[[vdTexManager sharedManager] loadTexture:@"sprite.png"]]; // We are creating a new shape (shapes are sprites) and assign it a new texture
																										 // loaded via the vdTexManager
	sprite.pos_x = (320/2)-(sprite.size_x/2); // We center ...
	sprite.pos_y = (480/2)-(sprite.size_y/2); // ... the sprite ...
	[sprite addAction:vdCreateAction(self, @selector(rotate:))]; // ... and adding a new rotation action to the sprite (this will rotate the sprite with the given speed). 
										// The action will be released when the node gets destroyed
	[rootNode addChild:sprite]; // Adding the sprite to the root node
	
    [window makeKeyAndVisible];
	return YES;
}


- (void)dealloc {
	[[vdKernel sharedKernel] destroy]; // This will remove the kernel, all loaded textures, all nodes attached to the root node and so completly.
	
    [window release];
    [super dealloc];
}


@end
